package com.example.liuke.guangguang.ui;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.Button;

import com.example.liuke.guangguang.R;
import com.example.liuke.guangguang.adapter.myrecyAdapter;

import java.util.ArrayList;
import java.util.List;

public class RecyActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private List<String> urllist;
    private myrecyAdapter adapter;
    private Button da, da2;

    private GridLayoutManager gridLayoutManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_recy);
        recyclerView = (RecyclerView) findViewById(R.id.myrecy);
        da = (Button) findViewById(R.id.da);
        da2 = (Button) findViewById(R.id.da2);
        da.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                adapter.add(0);
            }
        });

        da2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (urllist.size() >= 5) {
                    adapter.remove(4);
                }
            }
        });
        urllist = new ArrayList<>();
        urllist.clear();
       /* urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=a18b980dbd3533faeab6952e98d3fdca/9f510fb30f2442a76160eca6dd43ad4bd1130242.jpg");
        urllist.add("http://a.hiphotos.baidu.com/image/h%3D300/sign=ea4799136ed0f703f9b293dc38fa5148/faf2b2119313b07eaad49f0c00d7912397dd8c4d.jpg");
        urllist.add("http://b.hiphotos.baidu.com/image/h%3D300/sign=643f82257ff082023292973f7bfafb8a/63d9f2d3572c11df6098d9256f2762d0f703c26f.jpg");
        urllist.add("http://e.hiphotos.baidu.com/image/h%3D300/sign=a51250609422720e64cee4fa4bca0a3a/4a36acaf2edda3ccd03c4d220de93901203f92dc.jpg");
        urllist.add("http://h.hiphotos.baidu.com/image/h%3D300/sign=973e5976f7f2b211fb2e834efa806511/bd315c6034a85edf0ab7c12645540923dd5475ff.jpg");*/
        gridLayoutManager = new GridLayoutManager(this, 5);
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(5,StaggeredGridLayoutManager.VERTICAL);
        //gridLayoutManager.setOrientation(GridLayoutManager.HORIZONTAL);
        adapter = new myrecyAdapter(this, R.layout.recyitem, urllist);
        recyclerView.setLayoutManager(gridLayoutManager);
        //recyclerView.addItemDecoration(new RecyclerItemDecoration(0,6));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(adapter);
    }
}
